/**
* File:TimerSelector.h 
* Contains a class to enable users to set countdown time
*
* Copyright (c) 2008, J PENG
* All rights reserved.
**/

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace PJJTimer {

	/// <summary>
	/// Summary for TimeSelector
	///
	/// It define a preset of time for selection and allows users enter spepecified countdown time.
	/// </summary>
	public ref class TimeSelector : public System::Windows::Forms::Form
	{
	public:
		TimeSelector(void)
		{
			InitializeComponent();
			totalSeconds = 0;
			if(language != Languages::English) SetLanguages();
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~TimeSelector()
		{
			if (components)
			{
				delete components;
			}
		}

	private: System::ComponentModel::Container ^components;
	private: System::Windows::Forms::SplitContainer^  splitContainer;
	private: System::Windows::Forms::ComboBox^  timeCollection;
	private: System::Windows::Forms::Button^  button_select_ok;
	private: System::Windows::Forms::Button^  button_enter_ok;
	private: System::Windows::Forms::Label^  label_sep1;
	private: System::Windows::Forms::Label^  label_sep2;
	private: System::Windows::Forms::TextBox^  textBox_hours;
	private: System::Windows::Forms::TextBox^  textBox_seconds;
	private: System::Windows::Forms::TextBox^  textBox_minutes;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Label^  label2;

	private:
		int totalSeconds;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->splitContainer = (gcnew System::Windows::Forms::SplitContainer());
			this->button_select_ok = (gcnew System::Windows::Forms::Button());
			this->timeCollection = (gcnew System::Windows::Forms::ComboBox());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->textBox_seconds = (gcnew System::Windows::Forms::TextBox());
			this->textBox_minutes = (gcnew System::Windows::Forms::TextBox());
			this->textBox_hours = (gcnew System::Windows::Forms::TextBox());
			this->label_sep2 = (gcnew System::Windows::Forms::Label());
			this->label_sep1 = (gcnew System::Windows::Forms::Label());
			this->button_enter_ok = (gcnew System::Windows::Forms::Button());
			this->splitContainer->Panel1->SuspendLayout();
			this->splitContainer->Panel2->SuspendLayout();
			this->splitContainer->SuspendLayout();
			this->SuspendLayout();
			// 
			// splitContainer
			// 
			this->splitContainer->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
			this->splitContainer->Dock = System::Windows::Forms::DockStyle::Fill;
			this->splitContainer->IsSplitterFixed = true;
			this->splitContainer->Location = System::Drawing::Point(0, 0);
			this->splitContainer->Name = L"splitContainer";
			this->splitContainer->Orientation = System::Windows::Forms::Orientation::Horizontal;
			// 
			// splitContainer.Panel1
			// 
			this->splitContainer->Panel1->Controls->Add(this->button_select_ok);
			this->splitContainer->Panel1->Controls->Add(this->timeCollection);
			// 
			// splitContainer.Panel2
			// 
			this->splitContainer->Panel2->Controls->Add(this->label3);
			this->splitContainer->Panel2->Controls->Add(this->label2);
			this->splitContainer->Panel2->Controls->Add(this->label1);
			this->splitContainer->Panel2->Controls->Add(this->textBox_seconds);
			this->splitContainer->Panel2->Controls->Add(this->textBox_minutes);
			this->splitContainer->Panel2->Controls->Add(this->textBox_hours);
			this->splitContainer->Panel2->Controls->Add(this->label_sep2);
			this->splitContainer->Panel2->Controls->Add(this->label_sep1);
			this->splitContainer->Panel2->Controls->Add(this->button_enter_ok);
			this->splitContainer->Panel2->MouseClick += gcnew System::Windows::Forms::MouseEventHandler(this, &TimeSelector::Validate_textboxes_MouseClick);
			this->splitContainer->Size = System::Drawing::Size(186, 91);
			this->splitContainer->SplitterDistance = 39;
			this->splitContainer->SplitterWidth = 1;
			this->splitContainer->TabIndex = 0;
			// 
			// button_select_ok
			// 
			this->button_select_ok->DialogResult = System::Windows::Forms::DialogResult::OK;
			this->button_select_ok->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->button_select_ok->Location = System::Drawing::Point(125, 6);
			this->button_select_ok->Name = L"button_select_ok";
			this->button_select_ok->Size = System::Drawing::Size(31, 22);
			this->button_select_ok->TabIndex = 4;
			this->button_select_ok->Text = L"ok";
			this->button_select_ok->UseVisualStyleBackColor = true;
			this->button_select_ok->Click += gcnew System::EventHandler(this, &TimeSelector::button_select_ok_Click);
			// 
			// timeCollection
			// 
			this->timeCollection->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
			this->timeCollection->FormatString = L"t";
			this->timeCollection->FormattingEnabled = true;
			this->timeCollection->Location = System::Drawing::Point(27, 6);
			this->timeCollection->MaxDropDownItems = 16;
			this->timeCollection->Name = L"timeCollection";
			this->timeCollection->Size = System::Drawing::Size(88, 21);
			this->timeCollection->TabIndex = 3;
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->label3->Location = System::Drawing::Point(98, 6);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(17, 13);
			this->label3->TabIndex = 8;
			this->label3->Text = L"ss";
			this->label3->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->label2->Location = System::Drawing::Point(61, 6);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(23, 13);
			this->label2->TabIndex = 8;
			this->label2->Text = L"mm";
			this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->label1->Location = System::Drawing::Point(29, 6);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(19, 13);
			this->label1->TabIndex = 8;
			this->label1->Text = L"hh";
			this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
			// 
			// textBox_seconds
			// 
			this->textBox_seconds->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->textBox_seconds->Location = System::Drawing::Point(96, 19);
			this->textBox_seconds->MaxLength = 2;
			this->textBox_seconds->Name = L"textBox_seconds";
			this->textBox_seconds->Size = System::Drawing::Size(20, 20);
			this->textBox_seconds->TabIndex = 7;
			this->textBox_seconds->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
			this->textBox_seconds->TextChanged += gcnew System::EventHandler(this, &TimeSelector::ValidateTextBox_event_TextChanged);
			this->textBox_seconds->Leave += gcnew System::EventHandler(this, &TimeSelector::Validate_textBox_event_Leave);
			this->textBox_seconds->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &TimeSelector::textBox_key_Press);
			// 
			// textBox_minutes
			// 
			this->textBox_minutes->Location = System::Drawing::Point(62, 19);
			this->textBox_minutes->MaxLength = 2;
			this->textBox_minutes->Name = L"textBox_minutes";
			this->textBox_minutes->Size = System::Drawing::Size(20, 20);
			this->textBox_minutes->TabIndex = 7;
			this->textBox_minutes->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
			this->textBox_minutes->TextChanged += gcnew System::EventHandler(this, &TimeSelector::ValidateTextBox_event_TextChanged);
			this->textBox_minutes->Leave += gcnew System::EventHandler(this, &TimeSelector::Validate_textBox_event_Leave);
			this->textBox_minutes->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &TimeSelector::textBox_key_Press);
			// 
			// textBox_hours
			// 
			this->textBox_hours->Location = System::Drawing::Point(28, 19);
			this->textBox_hours->MaxLength = 2;
			this->textBox_hours->Name = L"textBox_hours";
			this->textBox_hours->Size = System::Drawing::Size(20, 20);
			this->textBox_hours->TabIndex = 7;
			this->textBox_hours->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
			this->textBox_hours->TextChanged += gcnew System::EventHandler(this, &TimeSelector::ValidateTextBox_event_TextChanged);
			this->textBox_hours->Leave += gcnew System::EventHandler(this, &TimeSelector::Validate_textBox_event_Leave);
			this->textBox_hours->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &TimeSelector::textBox_key_Press);
			// 
			// label_sep2
			// 
			this->label_sep2->AutoSize = true;
			this->label_sep2->Location = System::Drawing::Point(84, 22);
			this->label_sep2->Name = L"label_sep2";
			this->label_sep2->Size = System::Drawing::Size(10, 13);
			this->label_sep2->TabIndex = 6;
			this->label_sep2->Text = L":";
			// 
			// label_sep1
			// 
			this->label_sep1->AutoSize = true;
			this->label_sep1->Location = System::Drawing::Point(50, 22);
			this->label_sep1->Name = L"label_sep1";
			this->label_sep1->Size = System::Drawing::Size(10, 13);
			this->label_sep1->TabIndex = 6;
			this->label_sep1->Text = L":";
			// 
			// button_enter_ok
			// 
			this->button_enter_ok->DialogResult = System::Windows::Forms::DialogResult::OK;
			this->button_enter_ok->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->button_enter_ok->Location = System::Drawing::Point(125, 18);
			this->button_enter_ok->Name = L"button_enter_ok";
			this->button_enter_ok->Size = System::Drawing::Size(31, 22);
			this->button_enter_ok->TabIndex = 4;
			this->button_enter_ok->Text = L"ok";
			this->button_enter_ok->UseVisualStyleBackColor = true;
			this->button_enter_ok->Click += gcnew System::EventHandler(this, &TimeSelector::button_enter_ok_Click);
			// 
			// TimeSelector
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(186, 91);
			this->Controls->Add(this->splitContainer);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedToolWindow;
			this->MaximizeBox = false;
			this->MinimizeBox = false;
			this->Name = L"TimeSelector";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
			this->Text = L"  Set Countdown Time";
			this->TopMost = true;
			this->splitContainer->Panel1->ResumeLayout(false);
			this->splitContainer->Panel2->ResumeLayout(false);
			this->splitContainer->Panel2->PerformLayout();
			this->splitContainer->ResumeLayout(false);
			this->ResumeLayout(false);

		}
#pragma endregion

	public:
		void SetLanguages();
		//Generates a quartly time collection for 24 hours 
		void GenerateTimeCollection();
		int GetTotalSeconds();
		void ResetTextBoxes();

	private:
		//When textbox lose focus, check/restore the values inside the textboxes if empty
		void ValidateTextBoxesLossFocus();
		//Ensure at least one of the textbox value is valid
		//and limit the minute and second fields to be 59 maximum.
		void ValidateTextBoxesTextChanged();

		//time selection ok button pressed
		System::Void button_select_ok_Click(System::Object^  sender, System::EventArgs^  e);
		//Validate keys entered for hours, minutes and seconds from users
		System::Void textBox_key_Press(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e);
		System::Void Validate_textBox_event_Leave(System::Object^  sender, System::EventArgs^  e);
		System::Void Validate_textboxes_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e);
		System::Void button_enter_ok_Click(System::Object^  sender, System::EventArgs^  e);
		System::Void ValidateTextBox_event_TextChanged(System::Object^  sender, System::EventArgs^  e);
		System::Void TextBoxesSetSelected_event_Click(System::Object^  sender, System::EventArgs^  e);

};
}
